﻿define(['util', 'ajax'], function (util, ajax) {
    "use strict";

    var exports = {}, ViewModel;

    ViewModel = function() {
        var self = this;

        self.username = ko.observable();
        self.password = ko.observable();

        self.signIn = function() {
            ajax.post('Auth', { username: self.username(), password: self.password() }, { showSuccessMessage: true }).done(function(response) {
                if (response.redirectRequired) {
                    window.location = response.uri;
                }
            });
        };

        self.lostPassword = function() {
            var form = {
                UserNameOrEmailAddress: self.username()
            };
            ajax.post('authRecovery', form).done(function (response) {
                console.log(response);
            });
        };
    };
    exports.exec = function () {
        var viewModel = new ViewModel();
        ko.applyBindings(viewModel, document.getElementById('signin-form'));
    };

    return exports;
});